package activity.AllAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.hichip.campro.R;

import java.util.ArrayList;
import bean.RepeatTimeBean;

public class RepeatTimeAdapter extends BaseAdapter {

    private ArrayList<RepeatTimeBean> beans;
    private Context mContext;

    public RepeatTimeAdapter(Context context, ArrayList<RepeatTimeBean> beans) {
        this.mContext=context;
        this.beans=beans;
    }

    @Override
    public int getCount() {
        return beans.size();
    }

    @Override
    public RepeatTimeBean getItem(int position) {
        return beans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=View.inflate(mContext, R.layout.item_repeat_time,null);
            holder.cb_time=convertView.findViewById(R.id.cb_time);
            holder.tv_time=convertView.findViewById(R.id.tv_time);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        RepeatTimeBean bean= getItem(position);
        String title=" ";
        switch (bean.title) {
            case 0:
                title = mContext.getString(R.string.sunday);
                break;
            case 1:
                title =  mContext.getString(R.string.monday);
                break;
            case 2:
                title =  mContext.getString(R.string.tuesday);
                break;
            case 3:
                title =  mContext.getString(R.string.wednesday);
                break;
            case 4:
                title =  mContext.getString(R.string.thursday);
                break;
            case 5:
                title =  mContext.getString(R.string.friday);
                break;
            case 6:
                title =  mContext.getString(R.string.saturday);
                break;
        }
        holder.tv_time.setText(title+"    "+bean.str);
        return convertView;
    }

    public class ViewHolder{
        public CheckBox cb_time;
        public TextView tv_time;
    }
}
